/********************************************************/
/*	Author:		gong_libin			*/
/*	Date:		2017_11_01			*/
/*	File:		CmTrans.h			*/
/********************************************************/

#ifndef	_CMTRANS_H
#define	_CMTRANS_H

#include "CmTcp.h"
#include "CmMtLock.h"
#include "CmAdxDef.h"

#define	CM_LNK_ZERO		0x00
#define	CM_LNK_IDLE		0x01
#define	CM_LNK_BUSY		0x02

#define	CM_LNK_NUM		0x08

#define	CM_LNK_NAME		(char*)"CmTest"
#define	CM_LNK_ERRS		(char*)"Failed to CmTransInit"

typedef struct tagCmLink
{
	UCHAR		m_cTag;
	CmNet::CCmTcp	m_CTcp;
}CMLINK_S;

typedef struct tagCmFeed
{
	UINT		m_uiDsp;
	CMADXMSG_S	m_stMsg;
}CMFEED_S;

class CCmTrans;
typedef struct tagCmMark
{
	UINT		m_uiCursor;
	CCmTrans**	m_ppCTrans;
}CMMARK_S;

class CCmTrans
{
public:
	CCmTrans() {true == CmTransNew(CM_LNK_NAME) ? NULL : throw(CM_LNK_ERRS);}
	CCmTrans(char* pszName) {true == CmTransNew(pszName) ? NULL : throw(CM_LNK_ERRS);}
	virtual ~CCmTrans() {CmTransDel();}

	char* CmTransName();
	UINT CmTransGetOne();
	void CmTransCloseAll();
	CMLINK_S* CmTransLink();
	void CmTransMonitor(char* pszUrl);
	int CmTransConnectAll(char* pszUrl);
	void CmTransPayOne(CMLINK_S* pstLink);
	void CmTransTimeout(CMLINK_S* pstLink);
	void CmTransCloseOne(CMLINK_S* pstLink);
	int CmTransConnectOne(CMLINK_S* pstLink, char* pszUrl);

protected:

private:
	UINT			m_uiCur;
	char			m_szName[CM_BUFFER];
	CMLINK_S		m_stLink[CM_LNK_NUM];
	CmCls::CCmMtLock	m_CLock;

	void CmTransDel();
	bool CmTransNew(char* pszName);
};

#endif /* _CMTRANS_H */
